package cn.i7baozh.boot.learn.initializer;

import cn.i7baozh.boot.learn.initializer.config.MyConfig;
import cn.i7baozh.boot.learn.initializer.processor.ConfigChangeListener;
import cn.i7baozh.boot.learn.initializer.processor.MyPropertyProcessor;
import cn.i7baozh.boot.learn.thirdpropertyV2.MySourceV2;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * @author zhangbaoqi532
 * @date 2025/2/19
 */
public class MyInitializer implements ApplicationContextInitializer {
    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        ConfigurableEnvironment environment = applicationContext.getEnvironment();
        MyConfig.init(environment);

        MyPropertyProcessor myPropertyProcessor = new MyPropertyProcessor(environment);
        applicationContext.addBeanFactoryPostProcessor(myPropertyProcessor);

        applicationContext.addApplicationListener(new ConfigChangeListener());


        MySourceV2 mySourceV2 = new MySourceV2("v2");
        mySourceV2.setApplicationContext(applicationContext);
        environment.getPropertySources().addFirst(mySourceV2);

    }
}
